package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.mz.ozy.R;
import com.mz.ozy.bean.InviteBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */

public class MyInviteAdapter extends RecyclerView.Adapter<MyInviteAdapter.MyViewHolder> {



    private Context mContext;
    List<InviteBean.PageItemsBean> mBeanList;

    public MyInviteAdapter(Context context, List<InviteBean.PageItemsBean> mBeanList) {
        mContext = context;
        this.mBeanList = mBeanList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_my_invite, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final InviteBean.PageItemsBean bean = mBeanList.get(position);
        initGrade(holder.tvLevel,bean.getTdgrade());
        holder.usernameTv.setText(bean.getUsername());
        holder.timeTv.setText(bean.getRegtime());
        holder.tvTotalOrder.setText("订单总额 "+bean.getPricesum());


    }

    private void initGrade(TextView tvGrade, int grade) {
        switch (grade) {
            case 0:
                tvGrade.setText("");
                break;
            case 1:
                tvGrade.setText("V1");
                break;
            case 2:
                tvGrade.setText("V2");
                break;
            case 3:
                tvGrade.setText("V3");
                break;
            case 4:
                tvGrade.setText("V4");
                break;
            case 5:
                tvGrade.setText("V5");
                break;
            default:
                tvGrade.setText("V6");
                break;
        }
    }


    @Override
    public int getItemCount() {
        return mBeanList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.usernameTv)
        TextView usernameTv;
        @BindView(R.id.tv_level)
        TextView tvLevel;
        @BindView(R.id.timeTv)
        TextView timeTv;
        @BindView(R.id.tv_total_order)
        TextView tvTotalOrder;
        @BindView(R.id.ll_item)
        LinearLayout llItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }


    }


}
